package com.yupi.springbootinit.service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yupi.springbootinit.model.dto.production.*;
import com.yupi.springbootinit.model.dto.production.printingrecord.*;
import com.yupi.springbootinit.model.entity.User;
import com.yupi.springbootinit.model.entity.WorkflowTask;
import com.yupi.springbootinit.model.vo.WorkflowTaskVO;
import com.yupi.springbootinit.model.vo.production.*;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**

 生产执行服务
 */
public interface ProductionExecutionService {

    // 任务列表与统计
    Page<WorkflowTaskVO> pageAvailableTasks(Long userId, String status, long current, long size);

    Page<WorkflowTaskVO> pageMyProductionTasks(Long userId, String status, long current, long size);

    Map<String, Long> getTaskStatistics(Long userId);

    /**

     批量为任务列表附加“进度摘要”（清机状态 + 当前/下一工序）
     建议 Controller 在 includeProgress=true 时调用
     */
    void attachProgressSummary(List<WorkflowTaskVO> vos);
    // 任务详情
    WorkflowTaskVO getTaskDetail(Long taskId);

    // 任务认领（生产部）
    boolean claimTask(ProductionTaskClaimRequest request, Long userId, String userName, Long departmentId);

    // 旧版任务开始/完成（保留以兼容，仍由实现类标 @Deprecated）
    @Deprecated
    boolean startTask(ProductionTaskStartRequest request, Long userId, String userName);

    @Deprecated
    boolean completeTask(ProductionTaskCompleteRequest request, Long userId, String userName);

    // 烘粉清机流程
    boolean startPowderCleaning(StartCleaningRequest request, Long loginUserId, String loginUserName);

    boolean completePowderCleaning(CompleteCleaningRequest request, Long loginUserId, String loginUserName);

    CleaningRecordVO getCleaningRecord(Long taskId);

    // 生产流程（第一道工序）
    boolean startProduction(StartProductionFlowRequest request, Long loginUserId, String loginUserName);

    // 工序执行
    ProcessCompleteVO completeProcess(CompleteProcessRequest request, Long loginUserId, String loginUserName);

    boolean startProcess(StartProcessRequest request, Long loginUserId, String loginUserName);

    // 工序列表
    ProductionTaskDetailVO getProductionTaskDetail(Long taskId);

    /**
     * 获取与任务关联批次的PMC配置（粉末/清机设备）
     */
    PmcSetupVO getPmcSetup(Long taskId);

    // 操作员（生产部）
    List<OperatorVO> listOperators();

    // 烘粉清机任务列表
    Page<WorkflowTaskVO> pageCleaningTasks(Long userId, String status, long current, long size);

    // 生产任务列表
    Page<WorkflowTaskVO> pageProductionTasks(Long userId, String status, long current, long size);

    // 烘粉清机任务统计
    Map<String, Long> getCleaningTaskStatistics(Long userId);

    // 生产任务统计
    Map<String, Long> getProductionTaskStatistics(Long userId);

    void checkOperationPermission(WorkflowTask task, Long operatorId, String operatorName);

    /**
     * 获取单个任务的进度信息
     */
    ProductionProgressVO getTaskProgress(Long taskId);

    /**
     * 批量获取任务进度信息
     */
    Map<Long, ProductionProgressVO> batchGetTaskProgress(List<Long> taskIds);

}